package com.nbstar.film.spider.font.woff.table;

import com.nbstar.film.spider.font.woff.AbstractOTFDataStream;
import com.nbstar.film.spider.font.woff.AbstractWoffTable;
import com.nbstar.film.spider.font.woff.ByteBufferOTFDataStream;
import com.nbstar.film.spider.font.woff.WoffFont;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: wangxindong
 * @date: 2018/9/1-20:17
 */
public class MaximumProfileTable extends AbstractWoffTable {

    public static final String TAG = "maxp";

    private int version;
    private int numGlyphs;
    private int maxPoints;
    private int maxContours;
    private int maxCompositePoints;
    private int maxCompositeContours;
    private int maxZones;
    private int maxTwilightPoints;
    private int maxStorage;
    private int maxFunctionDefs;
    private int maxInstructionDefs;
    private int maxStackElements;
    private int maxSizeOfInstructions;
    private int maxComponentElements;
    private int maxComponentDepth;

    public MaximumProfileTable(WoffFont woffFont) {
        super(woffFont);
    }

    @Override
    public void read(WoffFont woffFont, AbstractOTFDataStream stream) throws IOException {
        stream.seek(offset);
        byte[] fontData = stream.read(compLength);
        byte[] inflateFont = inflateFontData(fontData);
        AbstractOTFDataStream data = new ByteBufferOTFDataStream(inflateFont);
        version = data.readInt();
        numGlyphs = data.readUnsignedShort();
        maxPoints = data.readUnsignedShort();
        maxContours = data.readUnsignedShort();
        maxCompositePoints = data.readUnsignedShort();
        maxCompositeContours = data.readUnsignedShort();
        maxZones = data.readUnsignedShort();
        maxTwilightPoints = data.readUnsignedShort();
        maxStorage = data.readUnsignedShort();
        maxFunctionDefs = data.readUnsignedShort();
        maxInstructionDefs = data.readUnsignedShort();
        maxStackElements = data.readUnsignedShort();
        maxSizeOfInstructions = data.readUnsignedShort();
        maxComponentElements = data.readUnsignedShort();
        maxComponentDepth = data.readUnsignedShort();
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public int getNumGlyphs() {
        return numGlyphs;
    }

    public void setNumGlyphs(int numGlyphs) {
        this.numGlyphs = numGlyphs;
    }

    public int getMaxPoints() {
        return maxPoints;
    }

    public void setMaxPoints(int maxPoints) {
        this.maxPoints = maxPoints;
    }

    public int getMaxContours() {
        return maxContours;
    }

    public void setMaxContours(int maxContours) {
        this.maxContours = maxContours;
    }

    public int getMaxCompositePoints() {
        return maxCompositePoints;
    }

    public void setMaxCompositePoints(int maxCompositePoints) {
        this.maxCompositePoints = maxCompositePoints;
    }

    public int getMaxCompositeContours() {
        return maxCompositeContours;
    }

    public void setMaxCompositeContours(int maxCompositeContours) {
        this.maxCompositeContours = maxCompositeContours;
    }

    public int getMaxZones() {
        return maxZones;
    }

    public void setMaxZones(int maxZones) {
        this.maxZones = maxZones;
    }

    public int getMaxTwilightPoints() {
        return maxTwilightPoints;
    }

    public void setMaxTwilightPoints(int maxTwilightPoints) {
        this.maxTwilightPoints = maxTwilightPoints;
    }

    public int getMaxStorage() {
        return maxStorage;
    }

    public void setMaxStorage(int maxStorage) {
        this.maxStorage = maxStorage;
    }

    public int getMaxFunctionDefs() {
        return maxFunctionDefs;
    }

    public void setMaxFunctionDefs(int maxFunctionDefs) {
        this.maxFunctionDefs = maxFunctionDefs;
    }

    public int getMaxInstructionDefs() {
        return maxInstructionDefs;
    }

    public void setMaxInstructionDefs(int maxInstructionDefs) {
        this.maxInstructionDefs = maxInstructionDefs;
    }

    public int getMaxStackElements() {
        return maxStackElements;
    }

    public void setMaxStackElements(int maxStackElements) {
        this.maxStackElements = maxStackElements;
    }

    public int getMaxSizeOfInstructions() {
        return maxSizeOfInstructions;
    }

    public void setMaxSizeOfInstructions(int maxSizeOfInstructions) {
        this.maxSizeOfInstructions = maxSizeOfInstructions;
    }

    public int getMaxComponentElements() {
        return maxComponentElements;
    }

    public void setMaxComponentElements(int maxComponentElements) {
        this.maxComponentElements = maxComponentElements;
    }

    public int getMaxComponentDepth() {
        return maxComponentDepth;
    }

    public void setMaxComponentDepth(int maxComponentDepth) {
        this.maxComponentDepth = maxComponentDepth;
    }

    @Override
    public String toString() {
        return "AbstractWoffTable{" +
                "tag='" + tag + '\'' +
                ", offset=" + offset +
                ", compLength=" + compLength +
                ", origLength=" + origLength +
                ", origChecksum=" + origChecksum +
                ", version=" + version +
                ", numGlyphs=" + numGlyphs +
                ", maxPoints=" + maxPoints +
                ", maxContours=" + maxContours +
                ", maxCompositePoints=" + maxCompositePoints +
                ", maxCompositeContours=" + maxCompositeContours +
                ", maxZones=" + maxZones +
                ", maxTwilightPoints=" + maxTwilightPoints +
                ", maxStorage=" + maxStorage +
                ", maxFunctionDefs=" + maxFunctionDefs +
                ", maxInstructionDefs=" + maxInstructionDefs +
                ", maxStackElements=" + maxStackElements +
                ", maxSizeOfInstructions=" + maxSizeOfInstructions +
                ", maxComponentElements=" + maxComponentElements +
                ", maxComponentDepth=" + maxComponentDepth +
                '}';
    }
}
